package com.platform.car.controller;

import com.platform.car.model.Capture;
import com.platform.car.model.Parkuse;
import com.platform.car.service.CaptureService;
import com.platform.car.service.ParkuseService;
import com.platform.common.config.Global;
import com.platform.common.page.Page;
import com.platform.common.utils.UserUtils;
import com.platform.upms.model.UpmsUser;
import com.platform.upms.model.json.Tip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/car/parkuse")
public class ParkuseController {
    @Autowired
    ParkuseService parkuseService;
    /**
     * 带分页的查询列表
     * @param page
     * @param modelMap
     * @return
     */
    @RequestMapping("/list")
    public String list(Page<Parkuse> page, ModelMap modelMap, Parkuse parkuse){
        if(!UserUtils.isHighestPower()) {
            parkuse.setOrgId(UserUtils.getUserOrgId());
        }
        String search=parkuse.getSearch();
        if (search !=null &&  "已撤销".equals(search)){
            parkuse.setStatus("0");
        }else if(search !=null &&  "已预约".equals(search)){
            parkuse.setStatus("1");
        }else if(search !=null &&  "使用中".equals(search)){
            parkuse.setStatus("2");
        }else if(search !=null &&  "已离开".equals(search)){
            parkuse.setStatus("3");
        }
        Page<Parkuse> parkuseList = parkuseService.findByPage(page, parkuse);
        modelMap.addAttribute("parkuseList",parkuseList);
        return  "/car/parkuse/list.jsp";
    }


    /**
     * 删除数据
     * @param ids
     * @return
     */
    @RequestMapping("/deleteDataByIds")
    @ResponseBody
    public Tip deleteDataByIds(String ids[]){
        try {
            parkuseService.deleteDataByIds(ids);
            return  new Tip("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return  new Tip(1,"删除失败");
        }
    }
}
